<?php

Class CategoryAction extends CommonAction{
	//分类列表视图
	Public function index(){
		// echo 1;
		import('Class.Category',APP_PATH);

		$cate = M('cate')->order('sort ASC')->select();
		// $this->cate = Category::unlimitedForLevel($cate);
		// $cate =Category::unlimitedForlayer($cate, 'cate');
		$cate = Category::getChilds($cate, 4);



		p($cate);


		// die;

		// $this->display();

	}

	Public function addCate(){
		// $this->display();
		$this->pid = I('pid',0,'intval');
		$this->display();
	}

	
	//添加分类表单
	Public function runAddCate(){
		// p($_POST);
		if(M('cate')->add($_POST)){
			$this->success('添加成功',U(GROUP_NAME . '/Category/index'));
		}else{
			$this->error('添加失败');
		}
	}
    //排序 

    public function sortCate(){
    	// p($_POST);
    	$db = M('cate');
    	// $db->where('id')->
    	foreach ($_POST as $id => $sort) {
    		$db->where(array('id' => $id))->setField('sort',$sort);

    		# code...
    	}
    	$this->redirect(GROUP_NAME . '/Category/index');
    }
}

?>